package com.haixiaoke.saas.enterprise.notice;

import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.annotation.TenantScope;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.core.redis.RedisCache;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.system.BaseController;
import com.haixiaoke.saas.system.domain.SysNotice;
import com.haixiaoke.saas.system.service.ISysNoticeService;
import com.haixiaoke.saas.system.service.impl.SysNoticeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公告 信息操作处理
 *
 * @author haixiaoke
 */
@RestController
@RequestMapping("/enterprise/notice")
public class EnterpriseNoticeController extends BaseController {
    @Autowired
    private ISysNoticeService noticeService;

    @Autowired
    private RedisCache redisCache;
    /**
     * 获取通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:notice:list')")
    @GetMapping("/list")
    @TenantScope
    public TableDataInfo list(SysNotice notice) {
        startPage();
        List<SysNotice> list = noticeService.selectNoticeList(notice);
        return getDataTable(list);
    }

    /**
     * 根据通知公告编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:notice:query')")
    @GetMapping(value = "/{noticeId}")
    @TenantScope
    public AjaxResult getInfo(@PathVariable Long noticeId) {
        return success(noticeService.selectNoticeById(noticeId));
    }

    /**
     * 获取公告高亮状态
     */
    @GetMapping(value = "/getNoticeHighlight")
    public AjaxResult getNoticeHighlight() {
        String s = redisCache.getCacheObject(SysNoticeServiceImpl.NOTICE_HIGHLIGHT_TIME) == null ? "0" : "1";


        return AjaxResult.success("success",s);
    }
}
